age = 42
print(id(age))  # 140724511312848

age = 43
print(id(age))  # 140724511312880

print("== " * 8)


class Person:
    def __init__(self, age):
        self.age = age


fab = Person(age=42)
print(fab.age, id(fab), id(fab.age))  # 42 1144854503328 140724511312848

fab.age = 25
print(fab.age, id(fab), id(fab.age))  # 25 1144854503328 140724511312304

print("== " * 8)

a = 14
b = 3
#       17     11     42   4.666666666666667 4 2 2744
print(a + b, a - b, a * b, a / b, a // b, a % b, a**b)

print("== " * 8)
# 1.75 1 -1.75 -2
print(7 / 4, 7 // 4, -7 / 4, -7 // 4)

print(-7 // 4, int(-1.75))

print(int("10110", base=2))  # 22

print(pow(10, 3), 10**3, 10**-3)  # 1000 1000 0.001

print(10 % 3, 10 % 4)  # 1 2
print("== " * 8)

print(pow(123, 4, 100))  # 41
print(1_000_000_000)  # 1000000000
print(0x_4_0_0)  # 1024
print("== " * 8)

print(int(True), int(False))
print(bool(""), bool(0), bool(0.0))  # False False False

print(1 + True, False + 42, 7 - True)  # 2 42 6

print(not True, True and True, False or True)  # False True True

print("== " * 8)

pi = 3.1415926536
radius = 4.5
area = pi * (radius**2)
print(area)  # 63.617251235400005

print("== " * 8)

import sys

print(sys.float_info)
print(pow(2, 64))  # 18446744073709551616

print(0.3 - 0.1 * 3)  # -5.551115123125783e-17

print("== " * 8)

print(len("abcd"))  # 4
print("abcd"[0], type("abcd"[1]))  # 'a'   <class 'str'>

print("== " * 8)

s = "This is unicode"
print(type(s))  # <class 'str'>

encode_s = s.encode("utf-8")
print(encode_s, type(encode_s))  # b'This is unicode' <class 'bytes'>
print(encode_s.decode(), type(encode_s.decode()))  # This is unicode <class 'str'>

bytes_obj = b"A bytes object"
print(type(bytes_obj))  # <class 'bytes'>

print("== " * 8)

s = "The trouble is you think you have time."
print(s[0], s[5])  # T r
print(s[:4])  # 'The '
print(s[4:])  # 'trouble is you think you have time.'
print(s[2:14])  # 'e trouble is'

print(s[2:14:3])  # 'erb '

print(s[:])  # 创建s的一个副本
print(s[::-1])  # 创建s的一个反向副本  '.emit evah uoy kniht uoy si elbuort ehT'

print("== " * 8)

greet_old = "Hello %s!"
print(greet_old % "Fabrizio")  # Hello Fabrizio!

greet_positional = "Hello {}!"
print(greet_positional.format("Fabrizio"))

greet_positional = "Hello {} {}!"
print(greet_positional.format("Fabrizio", "Romano"))  # 'Hello Fabrizio Romano!'

greet_positional_idx = "This is {0}! {1} loves {0}!"
print(
    greet_positional_idx.format("Python", "Heinrich")
)  # This is Python! Heinrich loves Python!

keyword = "Hello, my name is {name} {last_name}."
print(
    keyword.format(name="Fabrizio", last_name="Romano")
)  # Hello, my name is Fabrizio Romano.

print("== " * 8)

name = "Fab"
age = 42
# Hello! My name is Fab and I'm 42.
print(f"Hello! My name is {name} and I'm {age}.")  # 使用双引号

from math import pi

print(
    f"No arguing with {pi}, it's irrational..."
)  # No arguing with 3.141592653589793, it's irrational...

user = "heinrich"
password = "super-secret"
# Log in with: heinrich and super-secret
print(f"Log in with: {user} and {password}")
# Log in with: user='heinrich' and password='super-secret'
print(f"Log in with: {user=} and {password=}")

print("== " * 8)

t = ()
print(type(t))  # <class 'tuple'>
print(3 in (1, 2, 3))  # True

print("== " * 8)

a, b = 1, 2
print(a, b)  # 1 2
a, b = b, a
print(a, b)  # 2 1

print("== " * 8)

print(type([]))  # <class 'list'>
print(type(list()))  # <class 'list'>

x = [x + 5 for x in [2, 3, 4]]
print(x)  # [7, 8, 9]

print(list("Hello"))  # ['H', 'e', 'l', 'l', 'o']

print(list((1, 2, 3)))  # [1, 2, 3]

print("== " * 8)

a: list = [1, 2, 1, 3]
a.append(13)
print(a)  # [1, 2, 1, 3, 13]
print(a.count(1))  # 2
a.extend([5, 7])
print(a)  # [1, 2, 1, 3, 13, 5, 7]

print(a.index(13))  # 4

a.insert(0, [18])
print(a)  # [[18], 1, 2, 1, 3, 13, 5, 7]

a.pop()
print(a)  # [[18], 1, 2, 1, 3, 13, 5]

a.remove([18])
print(a)  # [1, 2, 1, 3, 13, 5]

a.reverse()
print(a)  # [5, 13, 3, 1, 2, 1]

a.sort()
print(a)  # [1, 1, 2, 3, 5, 13]


print(set(a))  # {1, 2, 3, 5, 13}

a.clear()
print(a)  # []

print("== " * 8)

a = list("hello")
print(a)  # ['h', 'e', 'l', 'l', 'o']
a.append(100)
print(a)  # ['h', 'e', 'l', 'l', 'o', 100]
a.extend((1, 2, 3))
print(a)  # ['h', 'e', 'l', 'l', 'o', 100, 1, 2, 3]

a.extend("abc")
print(a)  # ['h', 'e', 'l', 'l', 'o', 100, 1, 2, 3, 'a', 'b', 'c']

a = [1, 3, 5, 7]
print(min(a), max(a), sum(a))  # 1 7 16

from math import prod

print(prod(a))  # 105
print(len(a))  # 4

a = [1, 2, 3]
b = [4, 5, 6]
print(a * 2)  # [1, 2, 3, 1, 2, 3]
print(a + b)  # [1, 2, 3, 4, 5, 6]
a.append(b)
print(a)  # [1, 2, 3, [4, 5, 6]]

print("== " * 8)

from operator import itemgetter

a = [(5, 3), (1, 3), (1, 2), (2, 1), (4, 9)]
print(sorted(a))  # [(1, 2), (1, 3), (2, 1), (4, 9), (5, 3)]
print(sorted(a, key=itemgetter(0)))  # [(1, 3), (1, 2), (2, 1), (4, 9), (5, 3)]
print(sorted(a, key=itemgetter(0, 1)))  # [(1, 2), (1, 3), (2, 1), (4, 9), (5, 3)]

print(
    sorted(a, key=itemgetter(1), reverse=True)
)  # [(4, 9), (5, 3), (1, 3), (1, 2), (2, 1)]

print("== " * 8)

print(bytearray())  # bytearray(b'')
print(bytearray(10))  # bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
print(bytearray(range(5)))  # bytearray(b'\x00\x01\x02\x03\x04')

name = bytearray(b"Lina")
print(name)  # bytearray(b'Lina')


print(name.replace(b"L", b"l"))  # bytearray(b'lina')
print(name.endswith(b"na"))  # True

print(name.upper())  # bytearray(b'LINA')
print(name.count(b"L"))  # 1

print("== " * 8)

s = set()
print(s)  # set()
s.add(2)
s.add(3)
s.add(5)
print(s)  # {2, 3, 5}
s.add(1)
s.remove(1)
print(s)  # {2, 3, 5}

print(3 in s)  # True
s.add(3)
print(s)  # {2, 3, 5}

s2 = set([5, 7, 11, 13])
print(s2)  # {13, 11, 5, 7}

s3 = set("hello")
print(s3)  # {'l', 'o', 'h', 'e'}

s4 = set((1, 2, 3))
print(s4)  # {1, 2, 3}

s5 = {2, 3, 4, 5, 6}
print(type(s5), s5)  # <class 'set'> {2, 3, 4, 5, 6}

print("== " * 8)

s6 = frozenset([2, 3, 5, 7])
print(s6)  # frozenset({2, 3, 5, 7})

print("== " * 8)

dict1 = dict(a=1, z=-1)
dict2 = {"a": 1, "z": -1}
dict3 = dict(zip(["a", "z"], [1, -1]))
dict4 = dict([("a", 1), ("z", -1)])
dict5 = dict({"a": 1, "z": -1})

print(dict1 == dict2 == dict3 == dict4 == dict5)  # True
print("== " * 8)

zip1 = list(zip(list("hello"), list("12345")))
# [('h', '1'), ('e', '2'), ('l', '3'), ('l', '4'), ('o', '5')]
print(zip1)

zip2 = list(zip("hello", range(1, 6)))
# [('h', 1), ('e', 2), ('l', 3), ('l', 4), ('o', 5)]
print(zip2)

print("== " * 8)

d = {}
d["a"] = 1
d["b"] = 2
print(len(d))  # 2
print(d["a"])  # 1
print(d.get("a"))  # 1
print(d.get("c"))  # None

del d["a"]
print(d)  # {'b': 2}

d["c"] = 3
print("c" in d)  # True

d.clear()
print(d)  # {}

print("== " * 8)

d = dict(zip("hello", range(5)))
print(d)  # {'h': 0, 'e': 1, 'l': 3, 'o': 4}

print(d.keys())  # dict_keys(['h', 'e', 'l', 'o'])
print(d.values())  # dict_values([0, 1, 3, 4])
print(d.items())  # dict_items([('h', 0), ('e', 1), ('l', 3), ('o', 4)])

print(d.popitem())  # ('o', 4)
print(d)  # {'h': 0, 'e': 1, 'l': 3}

print(d.pop("l"))  # 3
print(d)  # {'h': 0, 'e': 1}

d.update({"another": "value"})
print(d)  # {'h': 0, 'e': 1, 'another': 'value'}

d.update(a=13)
print(d)  # {'h': 0, 'e': 1, 'another': 'value', 'a': 13}

print(d.get("a"))  # 13
print(d.get("d", 14))  # 14
print(d.get("d"))  # None

print("== " * 8)

d = {}
d.setdefault("a", 1)  # 返回 1
print(d)  # {'a': 1}

print("== " * 8)

d = {}
d.setdefault("a", {}).setdefault("b", []).append(1)
print(d)  # {'a': {'b': [1]}}

print("== " * 8)

from datetime import date, datetime, timedelta, timezone
import time
import calendar as cal

# from zoneinfo import ZoneInfo
today = date.today()
print(today)  # '2025-04-21'
print(today.ctime())  # 'Mon Apr 21 00:00:00 2025'
print(today.isoformat())  # '2025-04-21'
print(today.weekday())  # 0

print(cal.day_name[today.weekday()])  # 'Monday'

print((today.day, today.month, today.year))  # (21, 4, 2025)

print(today.timetuple())
# time.struct_time(
# tm_year=2025, tm_mon=4, tm_mday=21,
# tm_hour=0, tm_min=0, tm_sec=0,
# tm_wday=0, tm_yday=111, tm_isdst=-1)

print(time.time())  # 1745335006.9151735

print("== " * 8)

print(datetime.now())  # 2025-04-22 23:17:35.263996
print(datetime.utcnow())  # 2025-04-22 15:17:35.263996

now = datetime.now()
print(now.date())  # 2025-04-22
print(now.day, now.month, now.year)  # 22 4 2025
print(now.date() == date.today())  # True

print(now.time())  # 23:21:09.976297

# 23 21 58 750980
print(now.hour, now.minute, now.second, now.microsecond)

print(now.ctime())  # Tue Apr 22 23:22:34 2025

print(now.isoformat())  # 2025-04-22T23:23:04.663780

# time.struct_time(
# tm_year=2025, tm_mon=4, tm_mday=22,
# tm_hour=23, tm_min=23, tm_sec=28,
# tm_wday=1, tm_yday=112, tm_isdst=-1)
print(now.timetuple())

print(now.tzinfo)  # None
print(now.weekday())  # 1

utcnow = datetime.utcnow()

print(utcnow.tzinfo)  # None
